A Modeless Dialog


A Modeless Dialog

When a regular dialog (a modal dialog) opens, the user needs to complete or cancel the dialog to continue working on the main window of the program. In some applications, it is necessary that the user can interact with the main window while a dialog is open, this kind of dialogs are called modeless.
Cuando un diálogo regular (un diálogo Modal) se abre, el usuario necesita completar o cancelar el diálogo para continuar trabajando en la ventana principal del programa. En algunas aplicaciones, es necesario que el usuario pueda interactuar con la ventana principal mientras un diálogo está abierto, este tipo de diálogos son llamados Modeless.

Tip
You should use a modeless dialog ONLY if the application will benefit from it. If you create a modeless dialog when it is not needed, the user will be confused when interacting with the program.
Usted debe usar diálogos Modeles SOLAMENTE si la aplicación se beneficiará de este. Si usted crea un diálogo del tipo Modeless cuando éste no es necesario, el usuario se confundirá cuando interactúe con el programa.

Problem 1
Create a Window Application using Wintempla called GrayWindow to test Modeless Dialogs. After creating the application add a Dialog called LevelDlg using Tools > Add Wintempla Item... .
Cree una Aplicación de Ventana usando Wintempla llamada GrayWindow para probar los Diálogos Modeless. Después de crear la aplicación agregue un Diálogo llamada LevelDlg usando Tools > Add Wintempla Item... .

GrayWindowRun

GrayWindow.h
#pragma once //______________________________________ GrayWindow.h
#include "Resource.h"
#include "LevelDlg.h"

class GrayWindow: public Win::Window
{
public:
     GrayWindow()
     {
     }
     ~GrayWindow()
     {
     }
     LevelDlg levelDlg;
     ...
};


GrayWindow.cpp
#include "stdafx.h" //________________________________________ GrayWindow.cpp
#include "GrayWindow.h"

int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE, LPTSTR cmdLine, int cmdShow){
     GrayWindow app;
     app.CreateMainWindow(L"GrayWindow", cmdShow, IDI_GrayWindow, NULL, (HBRUSH)(COLOR_WINDOW + 1), hInstance);
     //_______________________________________________ BE SURE TO EDIT THE FOLLOWING LINE
     return app.MessageLoop(IDC_GrayWindow, app.levelDlg);
}

void GrayWindow::Window_Open(Win::Event& e)
{
     levelDlg.CreateDialog_(hWnd);
}

void GrayWindow::Window_Paint(Win::Event& e)
{
     CG::Gdi gdi(hWnd, true, false);
     RECT rect = {100, 200, 200, 400};
     CG::Brush brush(levelDlg.color);
     gdi.FillRect(rect, brush);
}


LevelDlg.h
#pragma once //_____________________________________________ LevelDlg.h
#include "resource.h"

class LevelDlg: public Win::Dialog
{
public:
     LevelDlg()
     {
          color = RGB(0, 0, 0);
     }
     ~LevelDlg()
     {
     }
     COLORREF color;
private:
     ...
};


LevelDlg.cpp
#include "stdafx.h" //_____________________________________________ LevelDlg.cpp
#include "LevelDlg.h"

void LevelDlg::Window_Open(Win::Event& e)
{
     //________________________________________________________ sldGray
     sldGray.SetRange(0, 255);
     sldGray.Position = 0;
}

void LevelDlg::sldGray_Hscroll(Win::Event& e)
{
     const int position = sldGray.HasPositionChanged();
     if (position < 0) return;
     color = RGB(position, position, position);
     ::InvalidateRect(::GetParent(hWnd), NULL, TRUE);
}

void LevelDlg::Window_Close(Win::Event& e)
{
     this->Destroy(); // Use this to close and destroy the Window
     this->hWndModeless = NULL;
}


© Copyright 2000-2021 Wintempla selo. All Rights Reserved. Jul 22 2021. Home